export default class Song {
  constructor({
    id,
    mid,
    singer,
    name,
    album,
    duration,
    image,
    url
  }) {
    this.id = id
    this.mid = mid
    this.singer = singer
    this.name = name
    this.album = album
    this.duration = duration
    this.image = image
    this.url = url
  }
}

// 创建一个工厂方法
export function songFactory(musicData) {
  return new Song({
    id: musicData.songid,
    mid: musicData.songmid,
    name: musicData.songname,
    album: musicData.albumname,
    duration: musicData.interval,
    image: `https://y.gtimg.cn/music/photo_new/T001R300x300M000${musicData.albummid}.jpg?max_age=2592000`,
    url: `http://thirdparty.gtimg.com/${musicData.songid}.m4a?fromtag=38`,
    singer: _filterSinger(musicData.singer)
  })
}

function _filterSinger(singer) {
  let tmp = []
  if (!singer) {
    return ''
  }
  singer.forEach(per => {
    tmp.push(per.name)
  })
  return tmp.join('|')
}
